from GoogleFreeTrans import Translator
class Tran():
    def __init__(self):
        self.transfer_en=None
        self.transfer_cn=None

        self.make_trans_cn()
        self.make_trans_en()
        #self.cn_to_ja('你好。')

    def make_trans_cn(self):
        try:
            self.transfer_cn = Translator.translator(src='zh-CN', dest='ja')
        except AttributeError:
            # print('rebulid')
            self.make_trans_cn()

    def make_trans_en(self):
        try:
            self.transfer_en=Translator.translator(src='en', dest='ja')
        except AttributeError:
            #print('rebulid')
            self.make_trans_en()

    def cn_to_ja(self,text):
        # print(self.transfer_cn.translate(text))
        return self.transfer_cn.translate(text)

    def en_to_ja(self,text):
        return self.transfer_en.translate(text)
        # print(self.transfer_en.translate(text))


if __name__ == '__main__':
    t=Tran()